package com.chance.cc.crawler.development.command.schedule.weibo;

import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.HttpPage;
import com.chance.cc.crawler.core.downloader.HttpRequest;
import com.chance.cc.crawler.core.downloader.http.HttpClientDownloader;
import com.chance.cc.crawler.core.downloader.http.HttpClientGenerator;
import com.chance.cc.crawler.core.downloader.proxy.SiteConfigProxyProvider;
import com.chance.cc.crawler.development.command.job.domain.weibo.WeiboTieCrawlerScheduleJob;
import com.chance.cc.crawler.development.command.job.domain.weibo.subscribe.WeiboApiSubscribeKeyCrawlerScheduleJob;
import com.chance.cc.crawler.development.command.schedule.CrawlerJobScheduleCommand;

/**
 * @Author Zhao.Hhuan
 * @Date Create in 2020/12/30 13:57
 * @Description
 *      微博
 **/
public class WeiboCrawlerJobSchedule {

    private static CrawlerJobScheduleCommand crawlerJobScheduleCommand =
            new CrawlerJobScheduleCommand("192.168.1.215",9589);


    public static void main(String[] args) {
//        deleteCrawlerJob(WeiboSearchKwCrawlerScheduleJob.publishCrawlerScheduleJobInfo().generateCrawlerTriggerKey());
      //  repubflishCrawlerJobInfo(WeiboPostCrawlerScheduleJob.publishCrawlerScheduleJobInfo().generateCrawlerTriggerKey());
//        repubflishCrawlerJobInfo(WeiboApiCrawlerScheduleJob.publishApiSubscribeDataCrawlerScheduleJobInfo().generateCrawlerTriggerKey());
        //微博帖子回复
//        repubflishCrawlerJobInfo(WeiboTieCrawlerScheduleJob.publishCrawlerScheduleJobInfo().generateCrawlerTriggerKey());


//        repubflishCrawlerJobInfo(WeiboApiSubscribeUserIdCrawlerScheduleJob.publishApiSubscribeDataCrawlerScheduleJobInfo().generateCrawlerTriggerKey());
//        repubflishCrawlerJobInfo(WeiboApiSubscribeUserIdInteractionCrawlerScheduleJob.publishApiSubscribeDataCrawlerScheduleJobInfo().generateCrawlerTriggerKey());
        repubflishCrawlerJobInfo(WeiboApiSubscribeKeyCrawlerScheduleJob.publishJob().generateCrawlerTriggerKey());
//        test();

    }

    /**
     * 重新发布调度
     * @param triggerKey
     */
    public static void repubflishCrawlerJobInfo(String triggerKey){
        crawlerJobScheduleCommand.republishCrawlerJob(triggerKey,"crawler_dev_host");
    }

    /**
     * 去除调度
     * @param triggerKey
     */
    public static void deleteCrawlerJob(String triggerKey){
        crawlerJobScheduleCommand.deleteCrawlerJob(triggerKey,"crawler_dev_host");
    }

    private static void test(){
        HttpConfig httpConfig = HttpConfig.me("test");
//        httpConfig.setProxy(proxy);
//        httpConfig.setUseProxy(false);

        HttpClientDownloader downloader = new HttpClientDownloader();
        downloader.setClientGenerator(new HttpClientGenerator());
        downloader.setProxyProvider(new SiteConfigProxyProvider());



        String url = "https://h5api.m.taobao.com/h5/mtop.taobao.detail.getdetail/6.0/?jsv=2.6.1&appKey=12574478&t=1623324046639&sign=5fe4ee7b4e6b7f178bb964f430e11764&api=mtop.taobao.detail.getdetail&v=6.0&isSec=0&ecode=0&AntiFlood=true&AntiCreep=true&ttid=2018%40taobao_h5_9.9.9&H5Request=true&type=jsonp&dataType=jsonp&callback=mtopjsonp1&data=%7B%22id%22%3A%22623337888932%22%2C%22hybrid%22%3A%22true%22%2C%22ttid%22%3A%221608030065155%40taobao_android_10.0.0%22%2C%22itemNumId%22%3A%22623337888932%22%2C%22itemId%22%3A%22623337888932%22%2C%22exParams%22%3A%22%7B%5C%22id%5C%22%3A%5C%22623337888932%5C%22%2C%5C%22hybrid%5C%22%3A%5C%22true%5C%22%2C%5C%22ttid%5C%22%3A%5C%221608030065155%40taobao_android_10.0.0%5C%22%7D%22%2C%22detail_v%22%3A%228.0.0%22%2C%22utdid%22%3A%221%22%7D";
        HttpRequest httpRequest = new HttpRequest();
        httpRequest.setUrl(url);
        httpRequest.addHeader("Cookie","cna=krlIGXvjR0ECATohFCJGKHyc");
//        httpRequest.addHeader("Cookie","w5i7FzOwzTgCATohFCIoU9Ne");
        httpRequest.addHeader("Host","h5api.m.taobao.com");
        httpRequest.addHeader("User-Agent","Mozilla/5.0 (Linux; U; Android 8.0.0; zh-CN; MI 5s Build/OPR1.170623.032) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 UWS/3.22.1.130 Mobile Safari/537.36 AliApp(TB/10.0.0) UCBS/2.11.1.1 TTID/1608030065155@taobao_android_10.0.0 WindVane/8.5.0 1080X1920 UT4Aplus/0.2.16");
        httpRequest.addHeader("Referer","https://h5.m.taobao.com/");

        HttpPage httpPage = downloader.download(httpRequest, httpConfig);
        System.out.println(httpPage.getRawText());
        System.out.println(httpConfig);
    }

}
